<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Date
 *
 * @author sebastian
 */
class Common_View_Formatter_Date extends Common_System_Date
{
 
    public static function getDateFrom($timestamp,$format = "d/m/Y", $java_timestamp = false)
    {
        if( $java_timestamp )
            $timestamp = $timestamp / 1000;
            
        return date($format, $timestamp);
    }

    public static function getDateFromISO8601($date_iso8601,$format="d/m/Y")
    {
        if($date_iso8601 != null)
        {
            $dateiso = explode("-",$date_iso8601);
            $year = $dateiso[0];
            $month = $dateiso[1];
            $day = $dateiso[2];

            $timestamp = mktime(0,0,0,$month,$day,$year);

            return date($format, $timestamp);
        }

        return "--";
    }

    public static function getPreviousDayFromISO8601($date_iso8601, $format="d/m/Y")
    {
        if($date_iso8601 != null)
        {
            $dateiso = explode("-",$date_iso8601);
            $year = $dateiso[0];
            $month = $dateiso[1];
            $day = $dateiso[2];

            $timestamp = mktime(0,0,0,$month,$day,$year) - self::DAY_SECONDS;

            return date($format, $timestamp);
        }

        return "";
    }

    public static function getMonthFromISO8601($date_iso8601)
    {
        if($date_iso8601 != null)
        {
            $dateiso = explode("-",$date_iso8601);            
            return $dateiso[1];
        }

        return "";
    }

    public static function getDateFromDefault($date_default,$format="Y-m-d")
    {
        if($date_default != null)
        {
            $date = explode("/",$date_default);
            $year = $date[2];
            $month = $date[1];
            $day = $date[0];

            $timestamp = mktime(0,0,0,$month,$day,$year);

            return date($format, $timestamp);
        }

        return "";
    }

}
?>